version: "3.8"

services:
  db:
    container_name: ${PG_HOST}
    image: postgres:latest
    env_file:
      # - .env
      - .env.template # для быстрого локального запуска
    environment:
      POSTGRES_DB: ${PG_DATABASE}
      POSTGRES_USER: ${PG_USER}
      POSTGRES_PASSWORD: ${PG_PASSWORD}
      POSTGRES_PORT: ${PG_HOST}
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - ./pgdata:/var/lib/postgresql/data/pgdata
    healthcheck:
      test: pg_isready -U ${PG_USER} -d ${PG_DATABASE}
      interval: 10s
      timeout: 30s
      retries: 5
      start_period: 30s
    restart: unless-stopped
    ports:
      - ${PG_PORT}:5432
    networks:
      - backend

  redis:
    container_name: redis
    image: redis:latest
    restart: unless-stopped
    ports:
      - 6379:6379
    networks:
      - backend

  api:
    container_name: api
    build: ./backend/
    env_file:
      # - .env
      - .env.template # для быстрого локального запуска
    depends_on:
      - db
      - redis
    ports:
      - 8001:8000
    networks:
      - backend
      - frontend

  front:
    container_name: front
    build: ./frontend/
    depends_on:
      - api
    ports:
      - 8080:3000
    networks:
      - frontend

networks:
  backend:
    driver: bridge

  frontend:
    driver: bridge
